package cn.doways.api.utils;

import cn.doways.api.dto.SaveSignDTO;
import cn.doways.api.dto.SignStudentDTO;
import cn.doways.api.vo.LateListVO;

import java.time.LocalDate;
import java.util.List;

/**
 * @ClassName ListUtils
 * @Description //TODO
 * @Author shellming
 * @Date 2019-09-08 15:03
 **/
public class ListUtils {
    public static List<LateListVO> getList(List<LateListVO> leave, List<SaveSignDTO> absent,String id, LocalDate startWeek){
        for (SaveSignDTO saveSignDTO:absent){
            LateListVO lateListVO=new LateListVO();
            lateListVO.setStartNumber(saveSignDTO.getTimeId());
            lateListVO.setEndNumber(saveSignDTO.getTimeId());
            lateListVO.setLeaveDate(DateUtils.asDate(startWeek.plusWeeks(saveSignDTO.getJustWeek().longValue()-1L).plusDays(saveSignDTO.getWeek()-1)));
            for (SignStudentDTO signStudentDTO:saveSignDTO.getStudentlist()){
                if (signStudentDTO.getId().equals(id)){
                    if (signStudentDTO.getStatus()==0){
                        lateListVO.setLeaveReason("旷课");
                    }else {
                        lateListVO.setLeaveReason("迟到");
                    }
                }
            }
            leave.add(lateListVO);
        }
        leave.sort((o1, o2) -> {
            if (o1.getLeaveDate().before(o2.getLeaveDate())){
                return 1;
            }else {
                return 0;
            }
        });
        return leave;

    }
}
